package com.osce.common.utils.http;

import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

/**
 * 人脸数据服务 - 远程调用处理器
 */
@Service
@Slf4j
public class FaceRemoteServiceProcessor {

    @Resource
    private RestTemplate restTemplate;

    /**
     * 调用远程服务添加人脸数据
     *
     * @param userId 用户ID
     * @param imageBase64 图片base64字符串
     * @return 是否成功
     */
    public boolean callFaceAddService(Integer userId, String imageBase64, String imageUrl) {
        try {
            // 创建请求对象
            ImageAO request = new ImageAO();
            request.setUserId(userId);
            request.setImageUrl(imageUrl);
            request.setImage(imageBase64);
            // 发送POST请求
            ResponseEntity<String> response = restTemplate.postForEntity("http://192.168.110.175:8089/faceAdd", request, String.class);

            return response.getStatusCode().is2xxSuccessful();
        } catch (Exception e) {
            log.error("远程服务调用异常", e);
            return false;
        }
    }



    /**
     * 谓用远程服务人脸识别
     * @param imageBase64 图片base64字符串
     * @return 比配结果
     */

    public CompareFaceRes callFaceCompareFacesForgeryService(String imageBase64) {
        try {
            // 创建请求对象
            CompareFaceRecognitionAO request = new CompareFaceRecognitionAO();
            request.setImage(imageBase64);
            // 发送post请求
            ResponseEntity<CompareFaceRes> response = restTemplate.postForEntity(
                    "http://192.168.110.175:8089/compareFaces-recognition",
                    request, CompareFaceRes.class);

            return response.getBody();
        } catch (Exception e) {
            log.error("远程服务调用异常", e);
            return null;
        }
    }

}
